package com.cwj.we.utils;

import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;

/**
 * Created by cwj on 2023-3-31.
 * <p>
 * Description:Json文件加载工具
 */
public class JsonFileUtil {

    public static String readTextFromSDcard(Context context, String fileName) {
        String resultString = null;
        try {
            InputStreamReader inputStreamReader = new InputStreamReader(context.getAssets().open(fileName), StandardCharsets.UTF_8);
            BufferedReader bufferedReader = new BufferedReader(
                    inputStreamReader);
            String line;
            StringBuilder stringBuilder = new StringBuilder();
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line);
            }
            inputStreamReader.close();
            bufferedReader.close();
            resultString = stringBuilder.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return resultString;
    }
}
